package com.tensquare.articlecrawler.pipeline;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.tensquare.articlecrawler.client.ArticleClient;
import com.tensquare.dto.Article;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

/**
 * 持久化类
 * @author Johnny.Chen
 *
 */
@Component
public class ArticleDBPipeline implements Pipeline {
	
	//注入远程调用的客户端
	@Autowired
	private ArticleClient articleClient;

	@Override
	public void process(ResultItems rs, Task task) {
		Article article = new Article();
		article.setTitle(rs.get("title"));
		article.setContent(rs.get("content"));
		article.setCreatetime(new Date());
		article.setState("1");
		article.setVisits(0);
		articleClient.add(article);
	}

	
}
